/*
package com.fw.application.controller;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.fw.application.controller.base.UserController;
import com.fw.application.controller.weChatOpen.WeRunData;
import com.fw.common.Builder;
import com.fw.common.IdXD;
import com.fw.mes.Result;
import com.fw.system.web.model.entity.*;
import com.fw.system.web.service.ITbCityCodeService;
import com.fw.system.web.service.ITbSysRuleService;
import com.fw.system.web.service.ITbUserService;
import com.fw.system.web.service.ITbWechatFootService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;

*/
/**
 * <p>
 * 微信步数表 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2023-03-28
 *//*

@RestController
@RequestMapping("/web/foot")
@Api(tags = "微信步数")
public class TbWechatFootController implements UserController {

    @Autowired
    private ITbWechatFootService footService;
    @Autowired
    private ITbUserService userService;
    @Autowired
    private IdXD idXD;
    @Autowired
    private ITbSysRuleService ruleService;
    @Autowired
    private ITbCityCodeService cityCodeService;

    @GetMapping("/getWeChatFool")
    @ApiOperation("获取微信步数")
    public Result getWeChatFool(@RequestBody WeRunData weRunData) {

        TbSysRule dayFoolRue = ruleService.getById(15);

        //todo 获取微信步数
        TbUser user = this.getUser();
        TbWechatFoot foot = footService.getOne(Wrappers.<TbWechatFoot>lambdaQuery().eq(TbWechatFoot::getUserId, user.getId())
                .last("and to_days(create_time) = to_days(now())"));
        if (foot == null) {
            Builder.of(TbWechatFoot::new)
                    .with(TbWechatFoot::setId, idXD.nextId())
                    .with(TbWechatFoot::setCreateTime, LocalDateTime.now())
                    .with(TbWechatFoot::setGainTime, weRunData.getTimestamp())
                    .with(TbWechatFoot::setWechatFoot, weRunData.getStep())
                    .with(TbWechatFoot::setUserId, user.getId()).build().insert();
            addUserFool(weRunData.getStep());
        } else if (foot.getWechatFoot() != weRunData.getStep()) {
            if (foot.getWechatFoot() < Integer.valueOf(dayFoolRue.getRuleValue())) {
                if (foot.getWechatFoot() + weRunData.getStep() <= Integer.valueOf(dayFoolRue.getRuleValue())) {
                    //更新今日步数
                    foot.setWechatFoot(foot.getWechatFoot() + weRunData.getStep()).updateById();
                    addUserFool(weRunData.getStep());
                } else {
                    //更新今日步数
                    foot.setWechatFoot(foot.getWechatFoot() + (Integer.valueOf(dayFoolRue.getRuleValue()) - foot.getWechatFoot())).updateById();
                    addUserFool(Integer.valueOf(dayFoolRue.getRuleValue()) - foot.getWechatFoot());
                }
            }
        }
        //更新今日步数
        user.setWechatFool(user.getWechatFool() + weRunData.getStep()).updateById();
        return new Result().success();
    }


    void addUserFool(Integer fool) {
        TbSysRule rule = ruleService.getById(10);
        TbUser user = this.getUser();
        if (user.getWechatFool() + fool >= Integer.valueOf(rule.getRuleValue()) * user.getNowCityCount()) {
            openCity();
            //累计步数增加
            user.setCountFool(user.getCountFool() + fool).updateById();
        } else {
            //累计步数增加
            user.setCountFool(user.getCountFool() + fool).updateById();
        }

    }

    void openCity() {

        TbUser user = this.getUser();
        if (user.getNowCityCount() <= 10) {
            TbCityCode one = cityCodeService.getOne(Wrappers.<TbCityCode>lambdaQuery().eq(TbCityCode::getSortCode, user.getNowCityCount() + 1));
            if (one != null) {
                Builder.of(TbUserCityJoin::new)
                        .with(TbUserCityJoin::setCreateTime, LocalDateTime.now())
                        .with(TbUserCityJoin::setIsType, 2)
                        .with(TbUserCityJoin::setCityCode, one.getId())
                        .with(TbUserCityJoin::setUserId, user.getId()).build().insert();
                user.setNowCityCount(user.getNowCityCount() + 1).updateById();
                if (user.getNowCityCount() >= 10) {
                    //todo 获取勋章
                    user.setIsMedal(1).updateById();
                }
            }
        }

    }
}

*/
